package com.atguigu.blog.article.service.impl;

import com.atguigu.blog.article.entity.Comment;
import com.atguigu.blog.article.entity.User;
import com.atguigu.blog.article.feign.CommentFeignClient;
import com.atguigu.blog.article.feign.UserFeignClient;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.blog.article.entity.Article;
import com.atguigu.blog.article.service.ArticleService;
import com.atguigu.blog.article.mapper.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【articles】的数据库操作Service实现
* @createDate 2024-12-25 14:55:47
*/
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article>
    implements ArticleService{

     @Autowired
     private UserFeignClient userFeignClient;

     @Autowired
     private CommentFeignClient commentFeignClient;

    @Override
    public Article doFindArticleById(Long id) {
        // 查询文章
        Article article = getById(id);
        //没有返回空值
        if (article == null){
            return null;
        }
        //查询用户信息
        User user = userFeignClient.queryUserById(article.getUserId());
        //查询评论列表
        List<Comment> commentList = commentFeignClient.queryCommentList(article.getArticleId());
        article.setUser(user);
        article.setCommentList(commentList);
        return article;
    }
}




